package com.mall.goods.service.impl;

import com.mall.goods.model.CategoryAttr;
import com.mall.goods.mapper.CategoryAttrMapper;
import com.mall.goods.service.ICategoryAttrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 分类属性关联表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-18
 */
@Service
public class CategoryAttrServiceImpl extends ServiceImpl<CategoryAttrMapper, CategoryAttr> implements ICategoryAttrService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addCategoryAttr(CategoryAttr categoryattr){
        return super.save(categoryattr);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(Integer categoryId){
        return super.removeById(categoryId);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateCategoryAttr(CategoryAttr categoryattr){
        return super.updateById(categoryattr);
    }

    @Override
    public CategoryAttr getById(Integer categoryId){
        return super.getById(categoryId);
    }

    @Override
    public List<CategoryAttr> selectList(CategoryAttr categoryattr){
        return super.list(getQueryWrapper(categoryattr));
    }

    @Override
    public Page<CategoryAttr> selectPage(Page<CategoryAttr> page, CategoryAttr categoryattr){
        return super.page(page, getQueryWrapper(categoryattr));
    }

    public LambdaQueryWrapper<CategoryAttr> getQueryWrapper(CategoryAttr categoryattr){
        return Wrappers.<CategoryAttr>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(categoryattr.getCategoryId()), CategoryAttr::getCategoryId, categoryattr.getCategoryId())
            .eq(ObjectUtils.isNotEmpty(categoryattr.getAttrId()), CategoryAttr::getAttrId, categoryattr.getAttrId())
        ;
    }
}
